﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace FlexiCommerce.Web.Admin.FlexiAdmin.Utility
{
    public partial class FileUploader : System.Web.UI.UserControl
    {
        public event EventHandler<ItemEventArgs> ImageSelected;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonUpload_Click(object sender, EventArgs e)
        {
            if (!FileUploadImage.HasFile)
            {
                return;
            }
            HttpPostedFile file = FileUploadImage.PostedFile;
            FileInfo fileInfo = new FileInfo(file.FileName);
            FileUploadImage.Dispose();
            if (!IsValidImageType(fileInfo.Extension))
            {
                return;
            }
            Components.Image img = FlexiCommerce.Context.Persister.SaveImage(file.InputStream);
            if (ImageSelected != null)
            {
                ImageSelected.Invoke(this, new ItemEventArgs(img));
            }
        }
        protected bool IsValidImageType(string extension)
        {
            return true;
        }
    }
}